<?php
class video{
	private $video_type;
	private $video_id;
	public function __construct($video_type,$video_id){
		$this->video_type=$video_type;
		$this->video_id=$video_id;
	}
	public function get_thumbnail(){
		if($this->video_id=='')return '';
		if($this->video_type=='youku'){
			return $this->get_youku_thumbnail($this->video_id);
		}else if($this->video_type=='tudou'){
			return $this->get_tudou_thumbnail($this->video_id);
		}
	}
	private function get_youku_thumbnail($video_id){
		$url = "http://v.youku.com/v_show/id_{$video_id}.html";
		$contents = file_get_contents($url);
		preg_match_all("/id=\"download\" href=\"(.*)\|\">/U",$contents,$m);
		if(isset($m)&&!empty($m[1])){
			$m_arr = explode("|",$m[1][0]);
		}
		return $m_arr[8];
	}
	private function get_tudou_thumbnail($video_id){
		$url = "http://www.tudou.com/programs/view/{$video_id}/";
		$contents = file_get_contents($url);
		preg_match_all("/<span class=\"s_pic\">(.*)<\/span>/U",$contents,$m);
		if(isset($m)&&!empty($m[1])){
			$m_arr = explode("|",$m[1][0]);
		}
		return $m_arr[0];
	}
}
//$v = new video('tudou','zLOlRwcl-6Y');
//echo $v->get_thumbnail();
?>
